home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / unix / setenv.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  1KB  |  57 lines

  1.  
  2. /*
  3.  *  SETENV.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  *
  9.  *  sets a local enviroment variable under 2.0, global env var under 1.3
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/libraries.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <fcntl.h>
  18. #include <libraries/dos.h>
  19.  
  20. #if INCLUDE_VERSION >= 36
  21. #include <dos/dostags.h>
  22. #include <clib/dos_protos.h>
  23. #endif
  24.  
  25. typedef struct Library Library;
  26.  
  27. extern Library *SysBase;
  28.  
  29. int
  30. setenv(varName, varStr)
  31. const char *varName;
  32. const char *varStr;
  33. {
  34. #if INCLUDE_VERSION >= 36
  35.     if (SysBase->lib_Version >= 37) {
  36.     SetVar(varName, varStr, -1, GVF_GLOBAL_ONLY);
  37.     } else
  38. #endif
  39.     {
  40.     long fh;
  41.     BPTR lock;
  42.  
  43.     if (lock = Lock("ENV:", SHARED_LOCK)) {
  44.         lock = CurrentDir(lock);
  45.         if (fh = Open(varName, 1006)) {
  46.         Write(fh, varStr, strlen(varStr));
  47.         Close(fh);
  48.         }
  49.         UnLock(CurrentDir(lock));
  50.     }
  51.     }
  52.     return(0);
  53. }
  54.  
  55.  
  56.  
  57.